package com.cskaoyan.service;

import com.cskaoyan.bean.regionvo.AreaVO;
import com.cskaoyan.bean.regionvo.CityVO;
import com.cskaoyan.bean.regionvo.ProvinceVO;
import com.cskaoyan.bean.regionvo.RegionVO;
import com.cskaoyan.mapper.MarketRegionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 创建日期: 2022/05/06 14:56
 *
 * @author shuyang
 */
@Service
public class RegionServiceImpl implements RegionService {
    @Autowired
    MarketRegionMapper regionMapper;

    @Override
    public RegionVO selectRegions() {
        byte provinceNum = 1;
        byte cityNum = 2;
        byte areaNum = 3;
        List<ProvinceVO> list = regionMapper.selectProvinceByType(provinceNum);
        for (ProvinceVO provinceVO : list) {
            Integer provinceVOId = provinceVO.getId();
            List<CityVO> children = regionMapper.selectCityByTypeAndCode(cityNum,provinceVOId);
            provinceVO.setChildren(children);
            for (CityVO child : children) {
                Integer id = child.getId();
                List<AreaVO> areaVOS = regionMapper.selectAreaByTypeAndCode(areaNum,id);
                child.setChildren(areaVOS);
            }
        }
        return new RegionVO(list);
    }
}
